import axios from 'axios'

const logapi = axios.create({
    baseURL: 'https://www.svom.cn/svomBA',
    // baseURL: 'https://www.svom-gwacn.cn/svomBA-dev',
    withCredentials: true,
    headers: {
      'Content-Type': 'application/json',
      // Authorization: `Bearer ${localStorage.getItem('accessToken')}` 
    }
  });
  
  logapi.interceptors.request.use(config => {
    const accessToken = localStorage.getItem('accessToken');
    if (accessToken) {
      config.headers.Authorization = `Bearer ${accessToken}`;
    }
    config.headers['Content-Type'] = 'application/json'; 
    config.params = {
      ...config.params,
      // userId: localStorage.getItem('userId'),
      // roleIds: localStorage.getItem('roleIds')
    };
    return config;
  });
  logapi.interceptors.response.use(
    response => response,
    error => {
      if (error.response?.status === 401) {
        localStorage.removeItem('accessToken');
        window.location.href = '/login';
      }
      return Promise.reject(error);
    }
  );
  
export default logapi;